﻿<Page x:Class="LinqDemo.Views.vwCountries"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
      xmlns:ViewModels="clr-namespace:LinqDemo.ViewModels" 
      xmlns:conv="clr-namespace:LinqDemo.Converters"
      mc:Ignorable="d" 
      d:DesignHeight="226" d:DesignWidth="864"
	  Title="vwCountries">

    <Grid>
        <Grid.Resources>
            <ViewModels:MainViewModel x:Key="MainVM" />
            <conv:NAConverter x:Key="NAConverter" />
            <conv:VisibilityConverter x:Key="VisibilityConverter" />
            <conv:TopBottomConverter x:Key="TopBottomConverter" />
            <conv:InversionConverter x:Key="InversionConverter" />
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="25" />
            <RowDefinition Height="25" />
            <RowDefinition Height="30" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <StackPanel Name="stkOptions" Grid.Row="0" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5,3,5,3" >
            <RadioButton Name="radAll" GroupName="ViewOptions" Content="Show all" Margin="0,0,5,0" Width="90" DataContext="{StaticResource MainVM}" IsChecked="{Binding IsOptionAllSelected, Mode=TwoWay}" />
            <!--IsChecked="{Binding IsOptionAllSelected, Mode=TwoWay}"-->
            <RadioButton Name="radFiltered" GroupName="ViewOptions" Content="Filtered view" Margin="5,0,0,0" Width="{Binding ElementName=radAll, Path=Width}" DataContext="{StaticResource MainVM}" />
            <!--IsChecked="{Binding IsOptionAllSelected, Mode=TwoWay, Converter={StaticResource InversionConverter}, ConverterParameter=bool}"-->
        </StackPanel>
        <ItemsControl Grid.Row="1" Grid.ColumnSpan="4" DataContext="{StaticResource MainVM}" ItemsSource="{Binding AllNavigationLinks}" >
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <TextBlock Margin="10,5,10,5">
                        <Hyperlink>
                            <TextBlock Text="{Binding NavText}">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Click">
                                        <i:InvokeCommandAction Command="{Binding NavFilterCommand}" CommandParameter="{Binding NavText}" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </TextBlock>
                        </Hyperlink>
                    </TextBlock>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
        <ItemsControl Grid.Row="2" Grid.ColumnSpan="4" DataContext="{StaticResource MainVM}" ItemsSource="{Binding AllRangeNavigationLinks}" >
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <TextBlock Margin="10,5,10,5">
                        <Hyperlink>
                            <TextBlock Text="{Binding NavText}">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Click">
                                        <i:InvokeCommandAction Command="{Binding NavFilterCommand}" CommandParameter="{Binding NavText}" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </TextBlock>
                        </Hyperlink>
                    </TextBlock>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
        <ScrollViewer Name="scrlAllData" Grid.Row="3" Grid.RowSpan="2" Margin="5" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" Visibility="{Binding ElementName=radAll, Path=IsChecked, Converter={StaticResource VisibilityConverter}}" >
            <DataGrid Name="dgrdAllData" AutoGenerateColumns="False" IsReadOnly="True" DataContext="{StaticResource MainVM}" ItemsSource="{Binding AllPagedCountries}">
                <DataGrid.Columns>
                    <DataGridTextColumn x:Name="dgcolCountryId" Header="Id" Binding="{Binding CountryId}" Visibility="Hidden" />
                    <DataGridTextColumn x:Name="dgcolCountryName" Header="Name" Binding="{Binding CountryName}" />
                    <DataGridTextColumn x:Name="dgcolCountryCode" Header="Code" Binding="{Binding CountryCode}" />
                    <DataGridTextColumn x:Name="dgcolGeographyName" Header="Geography" Binding="{Binding CountryCode}" />
                    <DataGridTextColumn x:Name="dgcolRegionName" Header="Region" Binding="{Binding RegionName}" />
                    <DataGridTextColumn x:Name="dgcolCountrySize" Header="Size (sq.km.)" Binding="{Binding CountrySize, Converter={StaticResource NAConverter}}" />
                    <DataGridTextColumn x:Name="dgcolPopulation" Header="Population" Binding="{Binding Population, Converter={StaticResource NAConverter}}" />
                    <DataGridTextColumn x:Name="dgcolInternetUsers" Header="Internet Users" Binding="{Binding InternetUsers, Converter={StaticResource NAConverter}}" />
                    <DataGridTextColumn x:Name="dgcolInternetPenetration" Header="Internet Penetration" Binding="{Binding InternetPenetration, Converter={StaticResource NAConverter}, StringFormat=#.##%}" />
                    <DataGridTextColumn x:Name="dgcolDataDate" Header="Data date" Binding="{Binding DataDate, StringFormat=MMM-yy}" />
                </DataGrid.Columns>
            </DataGrid>
        </ScrollViewer>

        <StackPanel Name="stkFilterOptions" Grid.Row="3" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5,3,5,3" Visibility="{Binding ElementName=radFiltered, Path=IsChecked, Converter={StaticResource VisibilityConverter}}" >
            <TextBlock Name="txtbInstruction" Text="Filter criteria" VerticalAlignment="Center" />
            <ComboBox Name="cmbFields" Width="150" HorizontalContentAlignment="Left" DataContext="{StaticResource MainVM}" ItemsSource="{Binding AllFilterConditions}" />
            <!--<ComboBox Name="cmbCount" Width="50" HorizontalContentAlignment="Center" />-->
            <StackPanel Name="stkCount" Orientation="Horizontal">
                <CheckBox Name="chkTop" Content="{Binding ElementName=chkTop, Path=IsChecked, Converter={StaticResource TopBottomConverter}}" DataContext="{StaticResource MainVM}" IsChecked="{Binding IsTopChecked}" Width="65" VerticalAlignment="Center" />
                <Slider Name="sldrCount" Width="200" VerticalAlignment="Center" DataContext="{StaticResource MainVM}" Value="{Binding FilterCount, Mode=TwoWay}" Minimum="{Binding MinFilterCount}" Maximum="{Binding MaxFilterCount}" />
                <TextBox Name="txtbCount" Width="30" IsReadOnly="True" HorizontalContentAlignment="Center" VerticalAlignment="Center" Text="{Binding ElementName=sldrCount, Path=Value}" />
            </StackPanel>
        </StackPanel>
        <ScrollViewer Name="scrlFilteredData" Grid.Row="4" Margin="{Binding ElementName=scrlAllData, Path=Margin}" HorizontalScrollBarVisibility="{Binding ElementName=scrlAllData, Path=HorizontalScrollBarVisibility}" VerticalScrollBarVisibility="{Binding ElementName=scrlAllData, Path=VerticalScrollBarVisibility}" Visibility="{Binding ElementName=radFiltered, Path=IsChecked, Converter={StaticResource VisibilityConverter}}" >
            <DataGrid Name="dgrdFilteredData" AutoGenerateColumns="False" IsReadOnly="True" DataContext="{StaticResource MainVM}" ItemsSource="{Binding AllFilteredCountries}">
                <DataGrid.Columns>
                    <DataGridTextColumn x:Name="dgcolFilteredCountryId" Header="Id" Binding="{Binding CountryId}" Visibility="Hidden" />
                    <DataGridTextColumn x:Name="dgcolFilteredCountryName" Header="Name" Binding="{Binding CountryName}" />
                    <DataGridTextColumn x:Name="dgcolFilteredCountryCode" Header="Code" Binding="{Binding CountryCode}" />
                    <DataGridTextColumn x:Name="dgcolFilteredValue" Header="{Binding FilteredHeader}" Binding="{Binding FilteredValue}" />
                </DataGrid.Columns>
            </DataGrid>
        </ScrollViewer>
    </Grid>
</Page>
